package cn.com.ddapp.ddm.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.VideoView;

import com.google.gson.Gson;

import org.json.JSONObject;

import butterknife.BindView;
import cn.com.ddapp.ddm.AppConfig;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.inter.OkUtilCallback;
import cn.com.ddapp.ddm.ui.empty.EmptyLayout;
import cn.com.ddapp.ddm.util.SPUtils;
import cn.com.ddapp.ddm.util.TDevice;
import okhttp3.Call;

public class GoodVideoActivity extends Activity {
    VideoView vv_video_detail;

    ProgressDialog progressDialog;
    String type;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.good_videoview);
        initView();
    }

    public void initView() {
        MediaController mediaController = new MediaController(this);
        vv_video_detail= (VideoView) findViewById(R.id.good_video);
        vv_video_detail.setMediaController(mediaController);

        vv_video_detail.setVideoURI(Uri.parse(OKUtilAPI.imgBaseUrl+ AppConfig.GOOD_VIDEO));

        progressDialog = new ProgressDialog(this, R.style.MyDialogStyle);

        progressDialog.setCancelable(true);
        progressDialog.setMessage("正在加载视频...");
        progressDialog.show();
        vv_video_detail.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                //(int) TDevice.getScreenWidth()
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT ,
                        LinearLayout.LayoutParams.MATCH_PARENT);
//                RelativeLayout.LayoutParams paramss = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                vv_video_detail.setLayoutParams(params);
                vv_video_detail.start();
            }
        });
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }
}
